﻿//-------------------------------------
// WBFSSync - WBFSSync.exe
//
// Copyright 2009 Caian (ÔmΣga Frøst) <frost.omega@hotmail.com>
//
// WBFSSync is Licensed under the terms of the Microsoft Reciprocal License (Ms-RL)
//
// ClipboardListView.cs:
//
// Classe que exibe os arquivos na Área de Transferência do programa
//
// Nota: o motivo pelo qual cada lista do aplicativo ganha uma classe derivada de uma ListView ao
// invés de uma super classe que englobe todas as funções é simplesmente manter o código organizado,
// mais simples, melhor customizável se necessário e livre de if()s para cada situação...
//
//-------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace WBFSSync.AeroControls
{
    class ClipboardListView : ListView
    {
        //----------------------- Variáveis

        Brush BackgroundBrush;

        //----------------------- Rotinas

        public ClipboardListView() : base()
        {
            DoubleBuffered = true;
            View = View.Details;
            OwnerDraw = true;
            Columns.Add(new ColumnHeader());
            ShowItemToolTips = true;
            BackgroundBrush = new SolidBrush(BackColor);
        }

        protected override void OnBackColorChanged(EventArgs e)
        {
            BackgroundBrush = new SolidBrush(BackColor);
            base.OnBackColorChanged(e);
        }

        protected override void OnResize(EventArgs e)
        {
            if (Columns.Count > 0) Columns[0].Width = Width - 17;
            base.OnResize(e);
        }

        public void UpdateClipboardList(String[] list)
        {
            SuspendLayout();
            Items.Clear();

            for (int i = 0; i < list.Length; i++)
            {
                ListViewItem item = new ListViewItem();
                item.Text = list[i];
                item.Tag = list[i];
                Items.Add(item);
            }

            ResumeLayout();
        }

        protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.HighSpeed;
            e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
            e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

            e.Graphics.FillRectangle(BackgroundBrush, e.Bounds);

            if ((e.ItemState & ListViewItemStates.Selected) != (ListViewItemStates)0)
            {
                e.Graphics.DrawImage(Skin.explorer_detail_selection_l_c, e.Bounds.X, e.Bounds.Y, 3, e.Bounds.Height);
                e.Graphics.DrawImage(Skin.explorer_detail_selection_m_c, e.Bounds.X + 3, e.Bounds.Y, e.Bounds.Width - 6, e.Bounds.Height);
                e.Graphics.DrawImage(Skin.explorer_detail_selection_r_c, e.Bounds.Right - 3, e.Bounds.Y, 3, e.Bounds.Height);
            }

            StringFormat format = new StringFormat();
            format.Trimming = StringTrimming.EllipsisCharacter;
            format.LineAlignment = StringAlignment.Near;
            format.Alignment = StringAlignment.Near;

            RectangleF bounds = new RectangleF(e.Bounds.Left + 4,
                e.Bounds.Top + (e.Bounds.Height - Skin.IconTitleFont.Height) / 2, Columns[e.ColumnIndex].Width - 5,
                Skin.IconTitleFont.Height);

            e.Graphics.DrawString(e.Item.Text, Skin.IconTitleFont, Brushes.Black, bounds, format);

            base.OnDrawSubItem(e);
        }
    }
}
